n = int(input())
s = list(map(int,input().strip()))
e = list(map(int,input().strip()))

def f(n,m):
    data = [abs(n-m),(10-n)+m,(10-m)+n]
    d_min = min(data)
##    print(data)
    return [data.index(d_min),d_min]


##print(f(0,9))
##print(f(1,7))
##print(f(2,5))
##print(f(9,1))

r = n- 1

cnt = 0

while r > -1:
    if r-1 != -1:
        opt = f(s[r],e[r])
        cnt += opt[-1]
        if opt[0] == 0:
            pass
        elif opt[0] == 1:
            for i in range(r-1,-1,-1):
                if s[i] == 9:
                    s[i] = 0
                else:
                    s[i] +=1
                    break
                        
        elif opt[0] == 2:
            for i in range(r-1,-1,-1):
                if s[i] == 0:
                    s[i] = 9
                else:
                    s[i] -= 1
                    break
            
    else:
        cnt += min(abs(s[r] - e[r]) , (10-s[r])+e[r],(10-e[r])+s[r])
##    print(s)
    r-=1

print(cnt)
    



